import Taro, { Component } from '@tarojs/taro'
import { Provider } from '@tarojs/redux'
import '@tarojs/async-await'

import Index from './pages/index'
import Public from './api/public'
import { setGlobalData } from './config/global_data'
import store from './store/store'

import './app.less'
// import less from 'less'
// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释：
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5')  {
//   require('nerv-devtools')
// }

class App extends Component {

  config = {
    pages: [
      "pages/loading/loading",
      "pages/consumer/index/index",
      "pages/consumer/my/my",
      "pages/business/index/index",
      "pages/business/my/my",
      "pages/business/resumer/resumer"
    ],
    subPackages: [
      {
        root: 'subPackages/subPackageF/',
        pages: [
          'myShop/myShop',
          'jobManage/jobManage',
          'balanceInfo/balanceInfo',
          'balanceDetail/balanceDetail',
          'balancePhone/balancePhone',
          'balanceRecharge/balanceRecharge',
          'shopApprove/shopApprove',
          'publicJob/publicJob',
          'selectPosition/selectPosition',
          'resumeInfo/resumeInfo',
          'equity/equity'
        ]
      },
      {
        root: 'subPackages/subPackageS/',
        pages: [
          'search/search',
          'jobInfo/jobInfo',
          'jobList/jobList',
          'rpInfo/rpInfo',
          'rpDetail/rpDetail',
          'imgInfo/imgInfo',
          'report/report',
          'brandInfo/brandInfo',
          'myResume/myResume',
          'protocol/protocol',
          'setting/setting',
          'aboutus/aboutus',
          'question/question',
          'questionDetail/questionDetail',
          'feedBack/feedBack',
          'portSubject/portSubject',
          'firmSubject/firmSubject'
        ]
      },
      {
        root: 'subPackages/examine/',
        pages: [
          'main/main',
          'detail/detail',
          'identity/identity'
        ]
      }
    ],
    window: {
      "backgroundTextStyle": "light",
      "navigationBarBackgroundColor": "#ffffff",
      "navigationBarTitleText": "",
      "navigationBarTextStyle": "black",
      "backgroundColor": "#F8F8F8",
      "onReachBottomDistance": 68
    },
    permission: {
      "scope.userLocation": {
        "desc": "你的位置信息将用于小程序位置接口的效果展示"
      }
    },
  }

  constructor() {
    super()
  }

  componentWillMount() {
    // less.modifyVars({
    //   '@themeColor':'red'
    // })
    Public.Theme().then((result) => {
      let { themeInfo } = result
      themeInfo = JSON.parse(themeInfo)
      Taro.setStorageSync('baseColor', themeInfo.baseColor)
      Taro.setStorageSync('welfareColor', themeInfo.welfareCorlor)
      Taro.setStorageSync('secondColor', themeInfo.secondColor)

    }).catch((err) => {
      console.log(err)
    });
    console.log('app路由params', this.$router.params)
    if (Taro.getEnv() === Taro.ENV_TYPE.WEAPP) {
      //判断是否扫码进入
      let scene = this.$router.params.query && this.$router.params.query.scene
      if (scene) {

      } else {
        //debug='debug'参数存在才会单独进入目标页面
        let params = this.$router && this.$router.params.query
        if (JSON.stringify(params) == '{}') {
          Taro.reLaunch({
            url: '/pages/loading/loading'
          })
        } else if (typeof params.debug == 'undefined' && params.debug != 'debug') {
          Taro.redirectTo({
            url: '/subPackages/examine/main/main'
          })
        }
      } 
    } else {
      Public.Person()

    }
  }

  componentDidMount() {
    setGlobalData("loginCounter", 0)
    setGlobalData("rpCounter", false)
  }

  componentDidShow() { }

  componentDidHide() { }

  componentCatchError() { }

  componentDidCatchError() { }

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render() {
    return (
      <Provider store={store}>
        <Index />
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
